<template>
  <div class="app-container">
    <div class="search-container">
      <el-form inline>
        <el-form-item label="名称">
          <el-input />
        </el-form-item>
        <el-button type="primary">搜索</el-button>
        <el-button type="primary" @click="operate('add')">新增</el-button>
      </el-form>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="姓名" align="center">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="合同" align="center">
        <template slot-scope="scope">
          {{ scope.row.contract }}
        </template>
      </el-table-column>
      <el-table-column label="上传时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.time }}
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{
            scope.row.status | statusFilterLabel
          }}</el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column
        class-name="status-col"
        label="是否在职"
        width="110"
        align="center"
      >
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{
            scope.row.status | statusFilterLabel
          }}</el-tag>
        </template>
      </el-table-column> -->
      <!-- <el-table-column align="center" prop="created_at" label="Display_time" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.display_time }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" width="220" align="center" fixed="right">
        <template slot-scope="scope">
          <!-- <el-button type="primary" size="mini" :disabled="scope.row.status == 0">发布</el-button> -->
          <!-- <el-button type="warning" size="mini" :disabled="scope.row.status == 1">停用</el-button> -->
          <el-button
            type="success"
            size="mini"
            @click="operate('edit', scope.row)"
            >修改</el-button
          >
          <el-button type="danger" size="mini">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="dialogVisible" :title="title" width="550px">
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="姓名">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="合同类型">
          <el-select v-model="form.person" placeholder="请选择合同类型">
            <el-option
              v-for="(item, index) in contractList"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="上传合同">
          <el-upload
            class="upload-demo"
            drag
            action="https://jsonplaceholder.typicode.com/posts/"
            multiple
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处，或<em>点击上传</em>
            </div>
            <div class="el-upload__tip" slot="tip">
              只能上传jpg/png文件，且不超过500kb
            </div>
          </el-upload>
        </el-form-item>

        <!-- <el-form-item label="Resources">
          <el-radio-group v-model="form.resource">
            <el-radio label="Sponsor" />
            <el-radio label="Venue" />
          </el-radio-group>
        </el-form-item>
        <el-form-item label="Activity form">
          <el-input v-model="form.desc" type="textarea" />
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="onSubmit">提交</el-button>
          <el-button @click="onCancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getList } from "@/api/table";

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        0: "success",
        1: "warning"
      };
      return statusMap[status];
    },
    statusFilterLabel(status) {
      const statusMap = {
        0: "已签",
        1: "待签"
      };
      return statusMap[status];
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      data: [
        {
          name: "张三",
          phone: "13788889999",
          contract: "入住合同",
          time: "2023-12-24 16:10:10",
          id: "450000199302104628",
          pageviews: 1165,
          status: 0,
          place: "经理"
        },
        {
          name: "张三",
          phone: "13788889999",
          contract: "入住合同",
          time: "2023-12-24 16:10:10",
          id: "450000199302104628",
          pageviews: 1165,
          status: 1,
          place: "员工"
        },
        {
          name: "张三",
          phone: "13788889999",
          contract: "入住合同",
          time: "2023-12-24 16:10:10",
          id: "450000199302104628",
          pageviews: 1165,
          status: 0,
          place: "员工"
        }
      ],
      dialogVisible: false,
      title: "新增",
      personList: [{ label: "张三", value: "0" }],
      numList: [
        { label: "每年", value: "0" },
        { label: "每月", value: "1" },
        { label: "每日", value: "2" }
      ],
      contractList: [
        { label: "改造合同", value: "0" },
        { label: "服务合同", value: "1" }
      ],
      form: {}
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      this.listLoading = true;
      this.list = this.data;
      this.listLoading = false;
      // getList().then(response => {
      //   this.list = response.data.items
      //   this.listLoading = false
      // })
    },
    operate(type, row) {
      if (type === "add") {
        this.dialogVisible = true;
        this.title = "新增";
      } else if (type === "edit") {
        this.dialogVisible = true;
        this.title = "修改";
        this.form = JSON.parse(JSON.stringify(row));
      }
    },
    onSubmit() {
      this.$message("submit!");
    },
    onCancel() {
      this.dialogVisible = false;
    }
  }
};
</script>
<style scoped>
.line {
  text-align: center;
}
</style>
